<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    let obj1 = {
      name: '小刚',
      age: 13,
      gander: '男'
    }
    let obj2 = {
      name: '小刚',
      age: 13,
      gander: '男'
    }
    function isEquit(first, second) {
      //通过 object.keys()的方法将对象键名转成数组
      const arr1 = Object.keys(first)
      const arr2 = Object.keys(second)
      //比较两个对象的长度，若长度不等，也就没有要进行后面的验证了，直接返回 false
      if (arr1.length != arr2.length) return false
      // 通过上面的验证后，遍历对象，看对象的值是否相等
      for (const k in first) {
        if (first[k] !== second[k]) return false
      }
      return true
    }
    console.log(isEquit(obj1, obj2))
    console.log(JSON.stringify(obj1) == JSON.stringify(obj2));
  </script>
</body>

</html>